#ifndef __MAIL_OP__H___    
#define __MAIL_OP__H___

#include <interface/data_op/mail.h>

namespace aot{ namespace data{

class mail_account_info_impl : public imail_account_info
{
public:
    virtual ~mail_account_info_impl(){;}
    mail_account_info_impl()
    {
        active = 0;
        mail_type = 0;

        email = &email_impl;
        mail_server = &mail_server_impl;
        smtp = &smtp_impl;
        mail_account = &mail_account_impl;
        mail_pwd = &mail_pwd_impl;
        create_datetime = &create_datetime_impl;
    }
public:
    virtual bool clone(imail_account_info** out) 
    {
        mail_account_info_impl* p = new mail_account_info_impl();
        *out = p;
        return p->assign(this);
    }
    virtual bool assign(const imail_account_info* in) 
    {
        if (NULL==in)
            return false;

        mail_account_info_impl* p = (mail_account_info_impl*) in;
        *this = *p;

        email = &email_impl;
        mail_server = &mail_server_impl;
        smtp = &smtp_impl;
        mail_account = &mail_account_impl;
        mail_pwd = &mail_pwd_impl;
        create_datetime = &create_datetime_impl;
        return true;

    }
public:
    aot::tt::str_impl email_impl;
    aot::tt::str_impl mail_server_impl;
    aot::tt::str_impl smtp_impl;
    aot::tt::str_impl mail_account_impl;
    aot::tt::str_impl mail_pwd_impl;
    aot::tt::str_impl create_datetime_impl;
};


class mail_info_impl : public imail_info
{
public:
    virtual ~mail_info_impl(){;}
    mail_info_impl()
    {
        id = 0;
        is_read = 0;

        mail_title = &mail_title_impl;
        mail_from = &mail_from_impl;
        mail_to = &mail_to_impl;
        recv_datetime = &recv_datetime_impl;
        body = &body_impl;
    }
    
public:
    virtual  bool clone(imail_info** out) 
    {
        mail_info_impl* p = new mail_info_impl();
        *out = p;
        return p->assign(this);
    }
    virtual  bool assign(const imail_info* in) 
    {
        if (NULL==in)
            return false;

        mail_info_impl* p = (mail_info_impl*) in;
        *this = *p;

        mail_title = &mail_title_impl;
        mail_from = &mail_from_impl;
        mail_to = &mail_to_impl;
        recv_datetime = &recv_datetime_impl;
        body = &body_impl;

        return true;
    }
public:
    aot::tt::str_impl mail_title_impl;
    aot::tt::str_impl mail_from_impl;
    aot::tt::str_impl mail_to_impl;
    aot::tt::str_impl recv_datetime_impl;
    aot::tt::str_impl body_impl;
};

class mail_op_impl : public aot::data::imail_op
{
public:
    mail_op_impl(void);
    virtual ~mail_op_impl(void);
public:    
    virtual bool insert(const imail_info* p, int* new_id);
    virtual bool del(int id); 
    virtual bool update(const imail_info* p);
    ///
    virtual bool read(int id, isqlite3_table** out);
    virtual bool read(int id, imail_info* out);
    virtual bool read(int id, imail_info** out);
    virtual bool get_mails_by_email(const char* mail, isqlite3_table** out);
  
    virtual bool get_mails_by_email_and_read_flag(const char* mail, int read_flag, isqlite3_table** out);
    virtual bool get_mails_by_sender(const char* sender_email, isqlite3_table** out);
    
    virtual int get_count_by_email(const char* mail);
    virtual bool get_page_mails_by_email(const char* mail, int count_per_page, int page_index, isqlite3_table** out);
   
    virtual int get_count_by_keyword(const char* mail, const char* keyword);
    virtual bool get_page_mails_by_keyword(const char* mail, const char* keyword, int count_per_page, int page_index, isqlite3_table** out);
    
    virtual bool add_account(const imail_account_info* p);
    virtual bool del_account(const char* mail);
    virtual bool update_account(const imail_account_info* p);
   
    virtual bool read_all_account( isqlite3_table** out);
    virtual bool read_account(const char* mail, isqlite3_table** out);
    virtual bool read_account(const char* mail, imail_account_info* out);
    virtual bool read_account(const char* mail, imail_account_info** out);
};


}} /* end namespace aot/data*/

#endif // __MAIL_OP__H___
